<?php

namespace App\Controllers;

class Travel extends BaseController {

    public function getIndex() {
        // connect to the model
        $places = new \App\Models\Places();
        // retrieve all the records
        $records = $places->findAll();
        $table = new \CodeIgniter\View\Table();
        $headings = $places->fields;
        $displayHeadings = array_slice($headings, 1, 3);
        $table->setHeading(array_map('ucfirst', $displayHeadings));
        foreach ($records as $record) {
            $Link = anchor("travel/showme/$record->id",$record->link);
            $table->addRow($record->name,$record->description,$Link);
            
            
        }
        $template = [
                'table_open' => '<table cellpadding="5px">',
                'cell_start' => '<td style="border: 1px solid #dddddd;">',
                'row_alt_start' => '<tr style="background-color:#dddddd">',
                ];
        $fields = [
                'title' => 'Hong Kong Singer',
                'heading' => 'Hong Kong Singer',
                'footer' => 'Copyright wuyuheng'
                ];
        $table->setTemplate($template);
        $parser = \Config\Services::parser();
            return $parser->setData($fields)
                            ->render('templates\top') .
                    $table->generate() .
                    $parser->setData($fields)
                            ->render('templates\bottom');
    }

    public function getshowme($id) {
        // connect to the model
        $places = new \App\Models\Places();
        // retrieve all the records
        $record = $places->find($id);
        // get a template parser
         $table = new \CodeIgniter\View\Table();
         $table->addRow('Name',$record['name']);
         $table->addRow('date of birth',$record['born']);
         $table->addRow('achievement',$record['achievement']);
         $table->addRow('Gender',$record['Gender']);
         $table->addRow('Occupation',$record['description']);
         $table->addRow('Personal details',$record['link']);
         $table->addRow('Image','<img height=300px src="/image/'.$record['image'].'"/>');
         $template = [
            'table_open' => '<table cellpadding="5px">',
            'cell_start' => '<td style="border: 1px solid #dddddd;">',
            'row_alt_start' => '<tr style="background-color:#dddddd">',
        ];
        $table->setTemplate($template);
        
         $fields = [
            'title' => 'Hong Kong Singer',
            'heading' => 'Hong Kong Singer',
            'footer' => 'Copyright wuyuheng'
        ];
        $parser = \Config\Services::parser();
        // tell it about the substitions
         return $parser->setData($fields)
                        ->render('templates\top') .
                $table->generate() .
                        $parser->setData($fields)
                        ->render('templates\bottom');
    }

}
